package com.seednia.foundation.framework.extension;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;

import com.seednia.foundation.framework.service.IService;
import com.seednia.foundation.framework.service.ServiceContainer;

public class ClosedAppListener implements ApplicationListener<ContextClosedEvent> /*, ApplicationListener<ContextStoppedEvent>*/ {

	private static final Log logger = LogFactory.getLog(ClosedAppListener.class);
	
	@Override
	public void onApplicationEvent(ContextClosedEvent ctxEvent) {
		
		for(IService service : ServiceContainer.getInstance().services()) {
			logger.info("Shutting down service '"+service.getId()+"'");
			service.shutdown();
		}
	}

}
